import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
# 读取数据
df = pd.read_csv('cars_price.csv')

font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)
# 数据清洗
df.dropna(subset=['price'], inplace=True)

# 1. 同车型价格分析
same_model = df.groupby('name')['price'].mean()
plt.figure(figsize=(12, 6))
same_model.plot(kind='bar')
plt.title('同车型价格分析', fontproperties=font)
plt.xlabel('车型',fontproperties=font)
plt.ylabel('平均价格 (万)',fontproperties=font)
plt.xticks(rotation=90)
plt.tight_layout()
plt.savefig('同车型价格分析.png')
plt.show()



